package com.wc.算法提高课.A第一章_动态规划.树形DP.数字转换;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/13 10:20
 * @description https://www.acwing.com/problem/content/1077/
 */
public class Main {
    /**
     * 思路：树形DP, x -> y 相当于x与y有一条双向边， 那我们求的相当于树的直径
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 50010, M = N << 1, idx = 1;
    static int[] sum = new int[N];
    static int[] h = new int[N], e = new int[M], ne = new int[M], w = new int[M];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = 2; i * j <= n; j++) {
                sum[i * j] += i;
            }
        }
        for (int i = 2; i <= n; i++) {
            if (sum[i] < i) {
                add(sum[i], i, 1);
                add(i, sum[i], 1);
            }
        }
        dfs(1, -1);
        out.println(res);
        out.flush();
    }

    static int res = 0;

    static void add(int a, int b, int c) {
        e[idx] = b;
        w[idx] = c;
        ne[idx] = h[a];
        h[a] = idx++;
    }

    static int dfs(int u, int fa) {
        int d1 = 0, d2 = 0;
        for (int i = h[u]; i > 0; i = ne[i]) {
            int j = e[i];
            if (j == fa) continue;
            int d = dfs(j, u) + w[i];
            if (d > d1) {
                d2 = d1;
                d1 = d;
            } else if (d > d2) d2 = d;
        }
        res = Math.max(res, d1 + d2);
        return d1;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
